<?php
	include("includes/secure.php");
	include("includes/config.php");
	include("includes/class/contract_company.class.php");
	
	$contract_company = new Contract_company(); 	
	$company = $contract_company->companyList();
	$eps = $contract_company->epsList();
	$arp = $contract_company->arpList();
	$afp = $contract_company->afpList();	
	
	$msg_info = $msg_alert = $msg_error = false;
	$_SESSION['msg_cool'] = '';
	$show_msg = 0;
			
	if(isset($_POST['addContractCompany']) && $_POST['addContractCompany'] == 1){
		$action = $_POST["action"];
		$data->hdvc_code = trim(mysql_real_escape_string($_POST['hdvc_code']));
		$data->coco_type = trim(mysql_real_escape_string($_POST['coco_type']));
		$data->coco_value = trim(mysql_real_escape_string($_POST['coco_value']));
		$data->coco_pay = trim(mysql_real_escape_string($_POST['coco_pay']));
		$data->coco_pay_value = trim(mysql_real_escape_string($_POST['coco_pay_value']));
		$data->coco_date_in = cambiarFormatoFecha($_POST['coco_date_in'],2);
		$data->coco_date_out = cambiarFormatoFecha($_POST['coco_date_out'],2);
		if (($_POST['coco_admin']) == ''){
		$data->coco_admin = 0;
		}
		else {
		$data->coco_admin = trim(mysql_real_escape_string($_POST['coco_admin']));
		}
		if (($_POST['coco_aporte_mutual']) == ''){
		$data->coco_aporte_mutual = 0;
		}
		else {
		$data->coco_aporte_mutual = trim(mysql_real_escape_string($_POST['coco_aporte_mutual']));
		}
		$data->eps_code = trim(mysql_real_escape_string($_POST['eps_code']));
		$data->arp_code = trim(mysql_real_escape_string($_POST['arp_code']));
		$data->afp_code = trim(mysql_real_escape_string($_POST['afp_code']));
		$data->coco_rep = trim(mysql_real_escape_string($_POST['coco_rep']));
		$data->coco_rep_ced = trim(mysql_real_escape_string($_POST['coco_rep_ced']));
		$data->coco_rep_tel1 = trim(mysql_real_escape_string($_POST['coco_rep_tel1']));
		$data->coco_rep_tel2 = trim(mysql_real_escape_string($_POST['coco_rep_tel2']));
		$data->coco_description = trim(mysql_real_escape_string($_POST['coco_description']));


		if ($data=$contract_company->addContractCompany($data) ){
			$msg_info = true;
			$_SESSION["msg_cool"] .= 'El contrato fue adicionado satisfactoriamente!!.<br />';
			echo "<script> window.location.href='listContractCompany.php?show_msg=3'</script>";
				
		}
		else{
			$msg_info = true;
			$_SESSION["msg_cool"] .= 'No pudo ser adicionada el Contrato!.<br />';
			echo "<script> window.location.href='listContractCompany.php?show_msg=1'</script>";
		}
	}
	
	if ( $msg_error )
		$show_msg = 1;
	elseif ( $msg_alert )
		$show_msg = 2;
	elseif ( $msg_info )
		$show_msg = 3;
?>